Page({
  data: {
    currentTab: '0',
    videoList: [],
    allVideos: [{
      id: 1,
      title: '非遗里的雅安-宋经杨氏小架48式太极拳',
      coverUrl: '/static/images/video-cover1.jpg',
      source: '雅安市文化馆',
      category: 3
    }, {
      id: 2,
      title: '非遗里的雅安-绿林派武术',
      coverUrl: '/static/images/video-cover2.jpg',
      source: '雅安市文化馆',
      category: 3
    }, {
      id: 3,
      title: '非遗里的雅安-周公山竹编',
      coverUrl: '/static/images/video-cover3.jpg',
      source: '雅安市文化馆',
      category: 5
    }, {
      id: 4,
      title: '非遗里的雅安-正月十五闹元宵',
      coverUrl: '/static/images/video-cover4.jpg',
      source: '雅安市文化馆',
      category: 1
    }]
  },

  onLoad() {
    this.loadVideoList()
  },

  // 加载视频列表数据
  loadVideoList() {
    const { currentTab, allVideos } = this.data
    let filteredVideos = allVideos
    
    // 根据currentTab筛选对应分类的视频
    if (currentTab !== '0') {
      filteredVideos = allVideos.filter(video => video.category === parseInt(currentTab))
    }
    
    this.setData({
      videoList: filteredVideos
    })
  },

  // 切换标签
  switchTab(e) {
    const index = e.currentTarget.dataset.index
    this.setData({
      currentTab: index.toString()
    })
    this.loadVideoList()
  },

  // 播放视频
  playVideo(e) {
    const id = e.currentTarget.dataset.id
    // TODO: 跳转到视频播放页面
    wx.navigateTo({
      url: `/pages/video/play?id=${id}`
    })
  }
})